package leetcode_2501_2600;

public class LeeCode_2597 {
    public static void main(String[] args) {
        System.out.println(beautifulSubsets(new int[]{2, 4, 6}, 2));
    }
    private static int beautifulSubsets(int[] nums, int k) {
        int[] ans = new int[1];
        ans[0] = -1;
        int[] dp = new int[1001 + 2 * k];
        dfs(nums, ans, dp, 0, k);
        return ans[0];
    }
    private static void dfs(int[] nums, int[] ans, int[] dp, int i,int k){
        if (i == nums.length){
            ans[0]++;
            return;
        }
        dfs(nums, ans, dp, i + 1, k);
        int x = nums[i] + k;
        if (dp[x - k] == 0 && dp[x + k] == 0){
            ++dp[x];
            dfs(nums, ans, dp, i + 1, k);
            --dp[x];
        }
    }
}
